package com.qys.livesMall.shop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qys.livesMall.shop.modal.entity.ShopGoodsSkuStocks;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author gmx
 * @since 2023-06-13
 */
@Mapper
public interface ShopGoodsSkuStocksMapper extends BaseMapper<ShopGoodsSkuStocks> {
    //库存递减
    @Update("UPDATE h2_shop_goods_sku_stocks SET num=num-#{num} WHERE id=#{id} AND num>=#{num}")
    int decount(@Param("id") Long skuId, @Param("num") Integer num);

    Integer totalStockNum(@Param("shopId")Long shopId);

    Integer totalStockNumOfUse(@Param("shopId")Long shopId);

    List<Long> getShopIdByNum(@Param("skuId")Long skuId, @Param("shopIds")List<Long> shopIds);

    Map getStockNumAndAmount(@Param("shopId")Long shopId);

    Integer getNumBySkuIds(@Param("skuIds")List<Long> skuIds);
}
